import info.gridworld.grid.Location;
import info.gridworld.actor.Bug;

public class ZBug extends Bug {
	private int steps;
	private int sideLength;
	private int isfinish;
	private int turns; // 旋转次数

	public ZBug(int n) {
		steps = 0;
		isfinish = 0;
		sideLength = n;
		turns = 0;
		setDirection(90);
	}

	public void act() {
		if (steps < sideLength && canMove()) {
			move();
			steps++;
		} else {
			if (isfinish > 1 || steps < sideLength) {
//        		isfinish = 0;
//        		steps = 0;
				return;
			} else if (isfinish % 2 == 0) {
				turns = 3;
				for (int i = 0; i < turns; i++) {
					turn();
				}
				isfinish++;
				steps = 0;
			} else if (isfinish % 2 == 1) {
				turns = 5;
				for (int i = 0; i < turns; i++) {
					turn();
				}
				isfinish++;
				steps = 0;
			}
		}
	}
}